//
//  InformationController.m
//  HarmonizePub
//
//  Created by rzhy on 2016/10/31.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "InformationController.h"
#import "Config.h"
#import "XHSegmentControl.h"
#import "XHMainScrollView.h"
#import "HealthyInfoList.h"
#import "InformationWebViewViewController.h"

@interface InformationController ()<XHSegmentControlDelegate, UIScrollViewDelegate, XHMainScrollViewDelegate>
@property (weak, nonatomic) IBOutlet XHSegmentControl *segmentControlView;
@property (weak, nonatomic) IBOutlet XHMainScrollView *mainScorllView;

@end

@implementation InformationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.mainScorllView.delegate = self;
    // 创建自定义segment
    self.segmentControlView.delagate = self;
    self.segmentControlView.itemsArray = @[@"健康百科", @"医院动态", @"健康教育"];
    [self.segmentControlView setSegmentWithNormalColor: [UIColor blackColor] selectColor:XHConfigColor fontSize:17.0f];

}


#pragma mark -- XHSegmentControlDelegate
- (void)selectSegmentControlWithIndex:(NSInteger)index
{

    [self refreshTableWithIndex:index];
 
}

- (void)refreshTableWithIndex: (NSInteger)index
{
    self.mainScorllView.healthyType = index + 1;
    [self.mainScorllView setContentOffset:CGPointMake(XHScreenWidth * index, 0) animated:YES];
}

#pragma mark -- UIScrollViewDelegate
//修改分页的小点
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.mainScorllView) {
        // 计算页数
        NSInteger index = scrollView.contentOffset.x / self.mainScorllView.bounds.size.width;
        [self.segmentControlView changeSegmentControlIndex: index];
        [self refreshTableWithIndex:index];
    }
}

#pragma mark -- XHMainScrollViewDelegate
- (void)tableViewdidSelectRowWithModel:(HealthyInfoList *)healthyInfoList
{
    InformationWebViewViewController *infoWebView = [[InformationWebViewViewController alloc] init];
    infoWebView.healthyInfoList = healthyInfoList;
    infoWebView.hidesBottomBarWhenPushed = YES;
    [self.navigationController  pushViewController:infoWebView animated:YES];
}

@end
